using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MapManager : MonoBehaviour
{
    public GameObject background;
    public GameObject mapElementExample;
    public Dictionary<string, GameObject> mapElements;
    public int map_y = 10;
    public int map_x = 10;
    
    private void CreateElements(GameObject element, int x,int y, float interval = 0)
    {
        var e_w = element.transform.localScale.x;
        var e_h = element.transform.localScale.y;
        float s_x=-(x*e_w+(x-1)*interval)/2+e_w/2, s_y=-(y*e_h+ (y - 1) * interval)/2+e_h/2;



        for (int i = 0; i < y; i+=1)
        {
            //acc_w = 0; acc_h = 0;
           
            for (int j = 0; j < x; j+=1)
            {
                
                var obj = Instantiate(element, this.transform.position+ new Vector3(s_x+j*(e_w+interval), s_y + i * (e_h + interval), 0), element.transform.rotation, this.transform);
                mapElements.Add(i.ToString()+","+j.ToString(), obj);
            }
        }
    }
    private void Awake()
    {
        mapElements = new();
    }
    // Start is called before the first frame update
    void Start()
    {

        CreateElements(mapElementExample, map_y, map_x, 0.2f);

    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
